from CloudEngine.core.StandardActor import StandardActor
from CloudEngine.core.VTActor import VTActor
from service.utils.transform import list_to_vtk_float_array


def render_attribute(service, attribute):
    if service.app.actorList.size() == 0:
        return
    ac: VTActor = service.app.actorList.getValue(0)
    if hasattr(ac, "is_standard_actor"):
        attr = ac.attributes[attribute]
        t = None
        if attr["size"] == 1:
            t = list_to_vtk_float_array(attr["dx"])
        else:
            t = list_to_vtk_float_array(attr["magtitude"])
        ac.scalar_bar_on(t)
        ac.scalar_bar.set_title(attribute)
        service.app.add_scalar_bar(ac.scalar_bar.instance)
    else:
        ac.active_attribute(attribute)
        service.app.add_scalar_bar(ac.scalar_bar.instance)
    service.app.state.to_attribute()
    service.app.render()
